package utils.primitif;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.Map;
import java.util.Map.Entry;

public class HashUtils {
	public static void putToHashAndIncrement(Hashtable<String,Integer> hash,String toPut){
		if(hash.containsKey(toPut)){
			hash.put(toPut, hash.get(toPut)+1);
		}else
			hash.put(toPut, 1);
	}
	public static ArrayList<Map.Entry<?, Integer>> sortValue(Hashtable<?, Integer> t){
		ArrayList<Map.Entry<?, Integer>> l = new ArrayList<Entry<?, Integer>>(t.entrySet());
		Collections.sort(l, new Comparator<Map.Entry<?, Integer>>(){
			public int compare(Map.Entry<?, Integer> o1, Map.Entry<?, Integer> o2) {
				return o2.getValue().compareTo(o1.getValue());
			}});
		return l;
	}
}
